package com.tjmc.company.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.company.api.entity.ResumeInvitationRecordsEntity;
import com.tjmc.company.api.enums.ResumeRecordStatusEnum;
import com.tjmc.company.service.ResumeInvitationRecordsService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 面试邀请记录表
 *
 * @author recruit
 * @date 2024-11-14 17:07:57
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/resumeInvitationRecords" )
@Tag(description = "resumeInvitationRecords" , name = "面试邀请记录表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ResumeInvitationRecordsController {

    private final ResumeInvitationRecordsService resumeInvitationRecordsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param resumeInvitationRecords 面试邀请记录表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getResumeInvitationRecordsPage(@ParameterObject Page page, @ParameterObject ResumeInvitationRecordsEntity resumeInvitationRecords) {
        LambdaQueryWrapper<ResumeInvitationRecordsEntity> wrapper = Wrappers.lambdaQuery(resumeInvitationRecords);
        return R.ok(resumeInvitationRecordsService.page(page, wrapper));
    }


    /**
     * 通过条件查询面试邀请记录表
     * @param resumeInvitationRecords 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject ResumeInvitationRecordsEntity resumeInvitationRecords) {
        return R.ok(resumeInvitationRecordsService.list(Wrappers.query(resumeInvitationRecords)));
    }

    /**
     * 新增面试邀请记录表
     * @param resumeInvitationRecords 面试邀请记录表
     * @return R
     */
    @Operation(summary = "新增面试邀请记录表" , description = "新增面试邀请记录表" )
    @SysLog("新增面试邀请记录表" )
    @PostMapping
    public R save(@RequestBody ResumeInvitationRecordsEntity resumeInvitationRecords) {
        resumeInvitationRecords.setResumeStatus(ResumeRecordStatusEnum.WAIT_CONFIRM);
        resumeInvitationRecords.setResumeStatusDesc(ResumeRecordStatusEnum.WAIT_CONFIRM.getDesc());
        //邀请过期时间：10天
        resumeInvitationRecords.setExpiredAt(DateUtil.offsetDay(new Date(), 10));
        boolean save = resumeInvitationRecordsService.save(resumeInvitationRecords);
        if (!save){
            return R.failed("新增失败");
        }
        return R.ok(resumeInvitationRecords);
    }

    /**
     * 修改面试邀请记录表
     * @param resumeInvitationRecords 面试邀请记录表
     * @return R
     */
    @Operation(summary = "修改面试邀请记录表" , description = "修改面试邀请记录表" )
    @SysLog("修改面试邀请记录表" )
    @PutMapping
    public R updateById(@RequestBody ResumeInvitationRecordsEntity resumeInvitationRecords) {
        return R.ok(resumeInvitationRecordsService.updateById(resumeInvitationRecords));
    }

    /**
     * 通过id删除面试邀请记录表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除面试邀请记录表" , description = "通过id删除面试邀请记录表" )
    @SysLog("通过id删除面试邀请记录表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(resumeInvitationRecordsService.removeBatchByIds(CollUtil.toList(ids)));
    }
}
